package com.cndw.kungfu.model.goods.app;

import java.util.Map;

import com.cndw.kungfu.domain.GoodsMode;
import com.cndw.kungfu.exception.ErrPopException;
import com.cndw.kungfu.ext.LanguageLib;
import com.cndw.kungfu.model.Context;

/**
 * 集齐多个东西获得一个物品
 * 
 * @author fantadust [9677889@qq.com]
 * @date 2012-11-5 下午4:25:08
 */
public class AppDo133 extends AppBase {

	@Override
	public boolean check() throws Exception {
		int haveNum = player.getPlayerBoxs().getStackNum(goodsMode.getGoodsId());
		if (haveNum < goodsMode.getValueA()) {
			throw new ErrPopException(LanguageLib.get("goods.use.neednum", goodsMode.getValueA()));
		}
		if (Context.getGoodsServer().getModeById(goodsMode.getValueB()) == null) {
			throw new ErrPopException(LanguageLib.get("comm.err.sys"));
		}

		return true;
	}

	@Override
	public Map<String, Object> run() throws Exception {
		player.getPlayerBoxs().costGoods(goodsId, goodsMode.getValueA() - 1);
		Context.getGoodsServer().giveGoods(playerId, goodsMode.getValueB(), 1);

		GoodsMode awardMode = Context.getGoodsServer().getModeById(goodsMode.getValueB());
		logString = LanguageLib.get("goods.use.getgoods", awardMode.getName());
		return msg;
	}
}
